CC=gcc
LD=ld
AS=nasm
ASFLAGS=--gstabs
ASSERT=-DASSERT
CFLAGS=-O0 -g -Wall -Wextra -ansi -nostdlib -fno-builtin -Iinclude $(ASSERT)
KERNIMG=koskern.bin
FPIMAGE=floppy.img
DIRS=asm kernel boot

export

.PHONY : all
all: $(DIRS)
	$(LD) -T linker.ld -o $(KERNIMG) 
	cat $(KERNIMG) end.o > $(KERNIMG).t
	mv $(KERNIMG).t $(KERNIMG)

.PHONY : $(DIRS)
$(DIRS):
	$(MAKE) -C $@

floppy: $(FPIMAGE) $(KERNIMG) $(BOOTSEC) 
	dd if=/dev/zero of=$(FPIMAGE) bs=512 count=2880
	mkdosfs $(FPIMAGE)
	dd conv=notrunc if=$(BOOTSEC) of=$(FPIMAGE) bs=512 count=1
	mcopy -i $(FPIMAGE) $(KERNIMG) ::/

.PHONY : clean
clean:
	rm -f *.o *~ $(KERNIMG) $(FPIMAGE)
	for i in $(DIRS); do \
		make -C $$i clean; \
	done
